typedef struct ListNode ListNode;

ListNode* reverseList(ListNode* head){
	ListNode* cur = head;
	ListNode* newhead = NULL;
	while (cur)
	{
		ListNode* next = cur->next; 
		cur->next = newhead;
		newhead = cur;
		cur = next;
	}
	return newhead;
}

bool isPalindrome(struct ListNode* head){

    ListNode* slow = head;
    ListNode* fast = head;
    ListNode* prev = head; 
    while (fast && fast->next)
    {
        prev = slow;
        slow = slow->next;
        fast = fast->next->next;
    }

    prev->next = NULL; 
    slow = reverseList(slow);  
	
    while (head)
    {
        if (head->val != slow->val)
        {
            return false;
        }

        head = head->next;
        slow = slow->next;
    }

    return true;
}